package com.example.zhaohang.employmentapp;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.LinearLayout;

import com.example.zhaohang.utils.ToastMake;
import com.example.zhaohang.weigit.MyButtonView;

import java.util.ArrayList;
import java.util.List;

public class EquipFixActivity extends BasicActivity implements View.OnClickListener  {

    private GridLayout mGlide;
    private List<String> mStrings = new ArrayList<>();
    private List<MyButtonView> mButtonViewList = new ArrayList<>();
    private EditText mEditText;
    private Button mButton;
    private int selectPostion = -1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView_V(R.layout.activity_equip_fix);

        //动态添加
        mGlide = (GridLayout) findViewById(R.id.gilde);
        mEditText = (EditText) findViewById(R.id.edittext);
        mButton = (Button) findViewById(R.id.name8);

        mButton.setOnClickListener(this);
        mStrings.add("乘客要求退款");
        mStrings.add("人为损坏");
        mStrings.add("座椅扫码失败");

        //获取窗口属性
        DisplayMetrics dm = new DisplayMetrics();
        //取得窗口属性
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        //窗口的宽度
        int screenWidth = dm.widthPixels;
        //窗口高度
        int screenHeight = dm.heightPixels;

        //动态添加按钮
        for (int i = 0; i < mStrings.size(); i++) {
            MyButtonView buttonView = new MyButtonView(EquipFixActivity.this);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(screenWidth*7/15,screenHeight/12);
            buttonView.setLayoutParams(params);
            mButtonViewList.add(buttonView);
            mGlide.addView(buttonView);
        }

        //可以增加动画或者改变其颜色等
        for (int i = 0; i < mButtonViewList.size(); i++) {
            final int b = i;
            mButtonViewList.get(i).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //设置成单选的
                    othearDo();
                    selectPostion = b;
                    mButtonViewList.get(b).getLinearLayout().setBackgroundDrawable(getResources().getDrawable(R.drawable.mybuttion_bcg_select));

                }
            });
        }
    }

    private void othearDo() {
        for (int i = 0; i < mButtonViewList.size(); i++) {
            mButtonViewList.get(i).getLinearLayout().setBackgroundDrawable(getResources().getDrawable(R.drawable.mybuttion_bcg));
        }
    }

    @Override
    public void onClick(View v) {


        String string = mEditText.getText().toString();
        if (string==null){
            return;
        }
        if (selectPostion==-1){
            ToastMake.showToast("请选择错误类型");
            return;
        }

        ToastMake.showToast(string+"==="+selectPostion);
        finish();
    }
}
